package com.yzycoc.coc.gf.sdk;

import cn.hutool.core.util.StrUtil;
import com.yzycoc.coc.gf.config.CocConfig;
import com.yzycoc.coc.gf.enums.KeyValues;
import com.yzycoc.coc.gf.function.BinDingPrivateFunction;
import com.yzycoc.coc.gf.function.BinDingPublicFunction;
import com.yzycoc.coc.gf.function.CocFunction;
import com.yzycoc.coc.gf.function.CocPrivateFunction;
import com.yzycoc.coc.gf.util.CocUtil;
import com.yzycoc.code.special.ApiSpecialCode;
import com.yzycoc.processor.event.Event;
import com.yzycoc.processor.event.EventPrivateMessage;
import com.yzycoc.processor.event.EventPublicMessage;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * 驱动
 * 创建时间： 2023/5/19
 *
 * @author yzy
 * @version 1.0
 **/
@Slf4j
public class SdkDriver implements Event {

    @Override
    public void eventPublicMessage(EventPublicMessage eventPublicMessage) {

        String msg = eventPublicMessage.getMsg();
        msg = msg.replace(ApiSpecialCode.AT("机器人") + " ", "")
                .replace(ApiSpecialCode.AT("机器人"), "")
                .replaceAll("  ", " ")
                .replaceAll("＃", "#")
                .replace("　", " ").trim();
        log.info("收到消息:{}", msg);
        String trigger = CocUtil.analysis(msg, KeyValues.TRIGGER.getConfig());
        if (StrUtil.isEmpty(trigger)) {
            return;
        }
        String text = msg.replace(trigger,"").replaceAll(" ","");
        boolean clans = CocFunction.lexicon(eventPublicMessage, msg, text);
        if (clans) return;
        if(eventPublicMessage.getMsg().contains(ApiSpecialCode.AT("机器人"))){

            CocConfig.API.sendPublicMsg(ApiSpecialCode.AT(eventPublicMessage.getSendUser()) +
                    " 请问您需要查询" + KeyValues.TRIGGER.getConfig().split(",")[0] + "什么信息呢？如果您不知道怎么使用，可以对我发送指令了解哦。\n "
                    + KeyValues.TRIGGER.getConfig().split(",")[0] + " 菜单 \n "
                    + KeyValues.TRIGGER.getConfig().split(",")[0] + " 文档 \n\n 目前国服暂未开放游戏数据API，无法查询国内部落的游戏数据！", eventPublicMessage);
        }

    }

    @Override
    public void eventPrivateMessage(EventPrivateMessage eventPrivateMessage) {
        String msg = eventPrivateMessage.getMsg();
        msg = msg.replace(ApiSpecialCode.AT("机器人") + " ", "")
                .replace(ApiSpecialCode.AT("机器人"), "")
                .replaceAll("  ", "")
                .replaceAll("＃", "#")
                .replace("　", " ");
        log.info("收到消息:{}", msg);
        String[] split = msg.split(" ");
        if (CocUtil.contains(msg, KeyValues.TRIGGER.getConfig())) {
            //部落
            if (split.length >= 2) {
                boolean clans = CocPrivateFunction.lexicon(eventPrivateMessage, msg, split);
                if (clans) return;
            }
            //数据
            CocConfig.API.sendPrivateMsg(
                    "请问您需要查询" + KeyValues.TRIGGER.getConfig() + "什么信息呢？如果您不知道怎么使用，可以对我发送指令了解哦。\n " + KeyValues.TRIGGER.getConfig() + " 菜单 \n " + KeyValues.TRIGGER.getConfig() + " 文档", eventPrivateMessage);
        }
    }

    @Override
    public List<String> subClient() {
        return null;
    }
}
